import java.util.ArrayList;
import java.util.Iterator;


/**
 * A set of 5 lucky numbers
 * 
 * @author Kao Vang
 *
 */
public class LuckyNumbers
{
	/* Attributes */
	private int[] numbers = new int[Constants.NUMBER_DIGIT_OF_FANTASY_FIVE]; // Create a array for 5 numbers
	private int numberOdd;				// Number of odd numbers this luckyNumber contained 
	private int numberEven;				// Number of even numbers this luckyNumber contained
	private boolean status;				// Active or desactive to display
	private int number_draw;			// The order in lucky numbers draw total
	
	
	/* Methods*/
	/**
	 * The default constructor of this class
	 */
	public LuckyNumbers() {
		
	}
	
	/**
	 * The constructor
	 * @param a - 1st number
	 * @param b - 2nd number
	 * @param c - 3th number
	 * @param d - 4th number
	 * @param e - 5th number
	 */
	public LuckyNumbers(int a, int b, int c, int d, int e ) {
		numbers[0] = a;
		numbers[1] = b;
		numbers[2] = c;
		numbers[3] = d;
		numbers[4] = e;
		this.status = true;
		this.numberOdd = this.numberEven = 0;
		this.number_draw =0;
		initNumberOddEven();	//Count & initial the odd and even numbers
	}

	
	/**
	 * Count & initial the odd and even numbers
	 */
	private void initNumberOddEven() {
		for(int i=0;i<Constants.NUMBER_DIGIT_OF_FANTASY_FIVE;i++){
			oddOrEvenNumber(numbers[i]);
		}
	}
	
	/**
	 * Increment Odd or Even number
	 * @param aNum - number to treat 
	 */
	private void oddOrEvenNumber(int aNum) {
		//this.numberEven += (numbers[0] % 2 == 0 )? 1:0;
		if (aNum % 2 == 0 ){
			this.numberEven++;
		}else{
			this.numberOdd++;
		}
	}
	
	/**
	 * Test 2 lucky if they constains the same numbers
	 * @param aLNumber - A lucky number to compare
	 * @return True if the numbers in a Number are the same as this numbers
	 */
	public boolean isEguals1(LuckyNumbers aLNumber) {
		//TODO A corriger
		boolean egals = true;
		int temp,j;
		for(int i=0;i<Constants.NUMBER_DIGIT_OF_FANTASY_FIVE;i++){
			temp = this.numbers[i];
			for(j=0;j<Constants.NUMBER_DIGIT_OF_FANTASY_FIVE;j++){
				if(aLNumber.getNumbers()[j] == temp){
					break;	// Fond number
				}
			}
			if(j>=5){ // Did not find number in aNumbers array
				egals = false;
				break;
			}
		}
		return egals;
	}
	
	/**
	 * Test 2 lucky if they constains the same numbers
	 * @param aLNumber - A lucky number to compare
	 * @return True if the numbers in a Number are the same as this numbers
	 */
	public boolean isEguals(LuckyNumbers aLNumber) {
		aLNumber.sortDigit();
		for(int i=0;i<numbers.length;i++){
			if(this.numbers[i] != aLNumber.getNumbers()[i] ){
				return false;
			}
		}
		return true;
	}
	
	/**
	 * Sort the digit in order growing
	 */
	private void sortDigit() {
		int digit_tem;
		for(int i=0;i<numbers.length;i++){
			for (int j=i+1; j<numbers.length;j++){
				if(numbers[i]>numbers[j]){
					digit_tem = numbers[i];
					numbers[i] = numbers[j];
					numbers[j]=digit_tem;
				}
			}
		}
	}
	
	/**
	 * Return a string of the numbers present in this luckyumber
	 */
	@Override
	public String toString() {
		return numbers[0]+" " +numbers[1]+" " +numbers[2]+" " +numbers[3]+" " +numbers[4];
	}
	
	/**
	 * Show lucky number is the status is True
	 */
	public void showLuckyNum() {
		if(status){
			System.out.println(this);
		}
	}
	
	/**
	 * Compare if the number odd are equal
	 * @param oddToCom - The number odd to compare 
	 * @return True if equal
	 */
	public boolean isOddEgual(int oddToCom){
		return this.numberOdd == oddToCom;
	}
	
	/**
	 * Test if a list of numbers exist in the lucky number
	 * @param l - List of numbers
	 * @return True if exist at leat 1 number in this lucky number
	 */
	public boolean isExistDigits(ArrayList<Integer> l) {
		int num_cur;
		Iterator<Integer> iterator = l.iterator();
		while (iterator.hasNext()) {
			num_cur = iterator.next();
			if(num_cur==numbers[0] || num_cur==numbers[1] || num_cur==numbers[2] || num_cur==numbers[3] || num_cur==numbers[4]){
				return true;
			}
		}
		return false;
	}
	
	/**
	 * Test if a number exist in this lucky number
	 * @param aNum - A nukber to test
	 * @return True if exist
	 */
	public boolean isExistADigit(int aNum) {
		if(aNum==numbers[0] || aNum==numbers[1] || aNum==numbers[2] || aNum==numbers[3] || aNum==numbers[4]){
			return true;
		}
	return false;
	}
	
	/**
	 * Show the lucky number informations
	 */
	public void showInfo(){
		System.out.println("Number: "+this);
		System.out.println("Status: "+this.status);
		System.out.println("[Odd, Even]: ["+this.numberOdd +", "+this.numberEven +"]");
	}
	
	/* Getter & Setter */
	public int getNumberOdd() {
		return numberOdd;
	}

	public void setNumberOdd(int numberOdd) {
		this.numberOdd = numberOdd;
	}

	public int getNumberEven() {
		return numberEven;
	}

	public void setNumberEven(int numberEven) {
		this.numberEven = numberEven;
	}

	public int[] getNumbers() {
		return numbers;
	}

	public boolean getStatus() {
		return status;
	}

	public void setStatus(boolean status) {
		this.status = status;
	}

	public int getNumber_draw() {
		return number_draw;
	}

	public void setNumber_draw(int number_draw) {
		this.number_draw = number_draw;
	}
	
	
}
